package cxf.spring.demo.gui.model;

import com.jgoodies.validation.ValidationResult;
import com.jgoodies.validation.Validator;
import com.jgoodies.validation.util.ValidationUtils;

/**
 * User: Vlad Vinichenko (akerigan@gmail.com)
 * Date: 27.04.2009
 * Time: 13:11:59
 */
public class UserBeanValidator implements Validator<UserBean> {

    public ValidationResult validate(UserBean userBean) {
        ValidationResult result = new ValidationResult();
        if (ValidationUtils.isEmpty(userBean.getLogin())) {
            result.addError("Login is required");
        }
        if (ValidationUtils.isEmpty(userBean.getFirstName())) {
            result.addError("First name is required");
        }
        if (ValidationUtils.isEmpty(userBean.getLastName())) {
            result.addError("Last name is required");
        }
        if (ValidationUtils.isEmpty(userBean.getPassword())) {
            result.addError("Password is required");
        } else if (!userBean.getPassword().equals(userBean.getPasswordConfirm())) {
            result.addError("Passwords don't match");
        }
        return result;
    }
}
